/**
 * 步骤分支选择
 */
 import { useForm } from "../../framework/common/context/metadata-context";
 import {getQuery} from "../../framework/common/utils"
 import "./approveStepReadonly.css"
import Operations from "./Operations";
import React, { useState } from "react";
import clsx from "clsx";
import { Tooltip , Input, Radio, Space, Checkbox, Spin } from "antd";
import get from "lodash/get";
import message from "../../framework/common/utils/message";
import request from "../../framework/common/utils/request";
import getInitiateFormData from "../../framework/common/utils/getInitiateFormData";
/**
 * approveSteps 步骤信息
 * model readonly只读 edit编辑模式
 * actual_steps 实际的步骤路径，不包含需要确认的路径
 */
import { useInject } from "../../framework/common/context/inject-context";
 export default function ({
    onChange,
    ind,
    item={}
}) {

    const injectInfo = useInject();//弹出框位置添加的上下文
    const itemKey = item.branch[0].id;

    return <Radio.Group 
            name={"branchradio" + ind}
            className="choose_steps_wrap" 
            value={injectInfo.checkList[itemKey]}
            onChange={
                (e)=>{
                    injectInfo.checkList[itemKey] = e.target.value;//给当前分支步骤增加

                    let keys = Object.keys(injectInfo.checkList);
                    let currentIndex=keys.findIndex(key=>key===itemKey);
                    keys.forEach((key,index)=>{
                        if(index>currentIndex){
                            delete injectInfo.checkList[key]
                        }
                    });//删除当前步骤后面其他需要选择分支的默认值

                    onChange({
                        branchStepIndex: e.target.value,//分支步骤索引
                        stepIndex: ind//步骤索引
                    })
                }
            }>
            <Space direction="vertical">
                {
                    item.branch.map(function(branch_item, b_ind){
                        return <Radio
                                className={clsx('i-radio select-step', branch_item.nodes && 'on')} 
                                data-key={branch_item.id}
                                key={branch_item.id}
                                value={b_ind}
                                data-path={ind + ".branch." + b_ind}
                                data-index={b_ind}
                            >
                                {branch_item.description}
                            </Radio>
                    })
                }
            </Space>
        </Radio.Group>;
}